﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//**************************************************************************************************
// 系统名称	：沿海集团任务管理系统
// 文件名称	： UserSession.cs
// 做成履历 ：
//      日期                    姓名            内容
//      2015-4-25       XXXXXXXXX           用户Session中的已登录会员的基本信息
//**************************************************************************************************
namespace CRM.UTIL
{
    /// <summary>
    /// 储存在Session中的已登录会员的基本信息。
    /// </summary>
    [Serializable]
    public class UserSession
    {
        /// <summary>
        /// 用户ID
        /// </summary>
        public object UserID;
        /// <summary>
        /// 公司ID
        /// </summary>
        public object CompanyID;
        /// <summary>
        /// 部门
        /// </summary>
        public object DepID;
        /// <summary>
        /// 是否管理员
        /// </summary>
        public object IsAdmin;
        /// <summary>
        /// 手机号:登陆帐户
        /// </summary>
        public object MobilePhone;
        /// <summary>
        /// 邮箱
        /// </summary>
        public object Email;
        /// <summary>
        /// 姓名
        /// </summary>
        public object FullName;
        /// <summary>
        ///是否可用
        /// </summary>
        public object IsActive;
        /// <summary>
        ///是否删除
        /// </summary>
        public object IsDel;
        /// <summary>
        /// 用户所有角色ID
        /// </summary>
        public object RoleId;

        /// <summary>
        /// 菜单
        /// </summary>
        public object MenuID;

        public object LoginName;

        public object Temp1;
        public object Password;
        public object Temp2;

        public RoleType RoleType;

        public bool CanExportAllData
        {
            get
            {
                return Common.CanExportAllData(LoginName.ToString());
            }
        }
        /// <summary>
        /// 初始化用户登录Session
        /// </summary>
        /// <param name="_user_id">用户ID</param>
        /// <param name="_login_name">登录帐号</param>
        /// <param name="_company_id">公司ID</param>
        /// <param name="_level">用户层级</param>
        /// <param name="valid_">是否冻结  0不冻结，1冻结</param>
        /// <param name="_user_name">姓名</param>
        public UserSession(object userID, object companyID, object depID, object isAdmin, object mobilePhone, object email,
            object fullName, object isActive, object isDel, object roleId, object menuID, object loginName,object temp1,object password,object temp2)
        {

            this.UserID = userID;
            this.CompanyID = companyID;
            this.DepID = depID;
            this.IsAdmin = isAdmin;
            this.MobilePhone = mobilePhone;
            this.Email = email;
            this.FullName = fullName;
            this.IsActive = isActive;
            this.IsDel = isDel;
            this.RoleId = roleId;
            this.MenuID = menuID;
            this.LoginName = loginName;
            Temp1 = temp1;
            Password = password;
            Temp2 = temp2;
            if ((string) IsAdmin == "Y")
            {
                RoleType = RoleType.Admin;
            }
            else
            {
                if (string.IsNullOrEmpty(Temp1.ToString()) && 
                    string.IsNullOrEmpty(Temp2.ToString()))
                {
                    //都为空
                    RoleType = RoleType.NotAdmin;
                }
                else//至少有一个不为空
                {
                    if (!string.IsNullOrEmpty(Temp1.ToString()) && 
                        string.IsNullOrEmpty(Temp2.ToString()))
                    {
                        //Temp1不为空 Temp2为空
                        RoleType = RoleType.Supplier;
                    }
                    else if (string.IsNullOrEmpty(Temp1.ToString()) &&
                             !string.IsNullOrEmpty(Temp2.ToString()))
                    {
                        //Temp1为空 Temp2不为空
                        RoleType = RoleType.NetPoint;
                    }
                    else
                    {
                        //都不为空
                        RoleType = RoleType.Supplier;
                    }
                }
            }
        }
    }
}
